<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>车辆管理</title>
    <meta name="decorator" content="default"/>
    <link href="${ctxStatic}/static_back/css/public.css" type="text/css" rel="stylesheet">
    <link href="${ctxStatic}/static_back/css/main.css" type="text/css" rel="stylesheet">
</head>

<body>
    <%--标题--%>
    <div class="top-section">
        <input id="btnCancel" class="back-link" type="button" value="&lt;" onclick="history.go(-1)"/>
        <h2><shiro:hasPermission name="air:airCar:edit">${not empty airCar.id?'修改车辆信息':'新增车辆'}</shiro:hasPermission></h2>
    </div>

    <%--表单主体--%>
    <div class="body-section white-body form-body">
        <form:form id="inputForm" modelAttribute="airCar" action="${ctx}/air/airCar/save" method="post" >
            <form:hidden path="id"/>
            <sys:message content="${message}"/>

            <div class="form-box" style="margin-bottom: 0">
                <div class="input-div">
                    <span>车牌号码</span>
                    <div>
                        <form:input path="carNumber" htmlEscape="false" class=""/>
                        <em>*</em>
                    </div>
                </div>
                <div class="input-div">
                    <span>类型</span>
                    <div>
                        <form:select path="type">
                            <form:options items="${fns:getDictList('bus_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div">
                    <span>所属单位</span>
                    <div>
                        <form:input path="belongUnit" htmlEscape="false" />
                    </div>
                </div>
                <div class="input-div">
                    <span>座位数</span>
                    <div>
                        <form:input path="seating" htmlEscape="false" cssStyle="width: 100px;" /> 个
                        <em>*</em>
                    </div>
                </div>
                <%--<div class="input-div">--%>
                    <%--<span>GPS</span>--%>
                    <%--<div>--%>
                        <%--<form:input path="gps" htmlEscape="false" />--%>
                    <%--</div>--%>
                <%--</div>--%>
            </div>

            <div class="form-box form-box-gary" style="margin-right: 40%;">
                <div class="input-div">
                    <span>司机</span>
                    <div>
                        <form:select id="drivers" path="driver.id" onchange="javascript:changeDriver();">
                            <form:option value="" label="待定"/>
                            <form:options items="${drivers}" itemLabel="name" itemValue="id"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div">
                    <span>联系电话</span>
                    <div>
                        <form:input id="phone" path="driver.phone" htmlEscape="false" disabled="true" />
                    </div>
                </div>
                <div class="input-div">
                    <span>对讲机</span>
                    <div>
                        <form:input id="interphone" path="driver.interphone" htmlEscape="false" disabled="true" />
                    </div>
                </div>
                <div class="input-div">
                    <span>服务站点</span>
                    <div>
                        <form:select path="airRidePoint.id" id="airRidePoints" onchange="javascript:changeaArRidePoint();">
                            <form:options items="${rides}" itemLabel="name" itemValue="id"/>
                        </form:select>
                    </div>
                </div>
                <div class="input-div">
                    <span>车辆调度</span>
                    <div>
                        <form:radiobuttons path="dispatchType" items="${fns:getDictList('is_join')}" itemLabel="label" itemValue="value"/>
                    </div>
                </div>
            </div>

            <div class="form-bottom">
                <shiro:hasPermission name="air:airCar:edit">
                    <input id="btnSubmit" class="btn btn-blue" type="submit" value="保 存"/>
                </shiro:hasPermission>
            </div>
        </form:form>
    </div>


    <script type="text/javascript">
        $(document).ready(function () {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
//                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });

        <%--$.ajax({--%>
            <%--url: "${ctx}/air/airRidePoint/getById",--%>
            <%--data: {id: ${airCar.airRidePoint.id}},--%>
            <%--type: "GET",--%>
            <%--dataType: "json",--%>
            <%--success: function (data) {--%>
                <%--console.log(data);--%>
                <%--var gps_position = data.data.lon + "," + data.data.lat;--%>
                <%--$("#gps_position").val(gps_position);--%>
            <%--},--%>
            <%--error: function (error) {--%>
                <%--console.log("error");--%>
                <%--console.log(error);--%>
            <%--}--%>
        <%--});--%>

        function changeDriver() {
            var val = $("#drivers").val();
            $.ajax({
                url: "${ctx}/air/airDriver/getDriver",
                data: {driverId: val},
                type: "GET",
                dataType: "json",
                success: function (driver) {
                    console.log("success");
                    $("#phone").val(driver.data.phone);
                    $("#interphone").val(driver.data.interphone);
                },
                error: function (error) {
                    console.log("error");
                    console.log(error);
                }
            });
        }

        function changeaArRidePoint() {
            var val = $("#airRidePoints").val();
            $.ajax({
                url: "${ctx}/air/airRidePoint/getById",
                data: {id: val},
                type: "GET",
                dataType: "json",
                success: function (data) {
                    console.log(data);
//                    $("#point").val(data.data.position);
//                    var gps_position = data.data.lon + "," + data.data.lat;
//                    $("#gps_position").val(gps_position);
                },
                error: function (error) {
                    console.log("error");
                    console.log(error);
                }
            });
        }
    </script>
</body>
</html>